package filters;

import interfaces.IMap;

import java.awt.Point;

public class Maximazer implements IFilter
{
	Point Points[][];
	public Maximazer()
	{
		Points = new Point[4][2];
		Points[0][0] = new Point(-1, 0);
		Points[0][1] = new Point(1, 0);
		
		Points[1][0] = new Point(0, -1);
		Points[1][1] = new Point(0, 1);
		
		Points[2][0] = new Point(-1, -1);
		Points[2][1] = new Point(1, 1);
		
		Points[3][0] = new Point(1, -1);
		Points[3][1] = new Point(-1, 1);	
	}
	@Override
	public int ApplyFilter(int Px, int Py, IMap map) 
	{		
		int cur = (int)map.Get(Px,Py);
		int cVect = (cur >> 24) & 255;
		cur = cur & 255;
		if(cVect==0)
			return cur;
		Point CPoints[] = Points[cVect-1];
		
		for(int i=0;i<2;i++)
		{
			int val = (int)map.Get(Px + CPoints[i].x,Py+ CPoints[i].y);		
			val = val & 255;
			if(val>cur)
				return 1;
		}		
		
		return cur;
	}
}
